package com.home.cop.sysinfo.service.impl;

import com.home.cop.sysinfo.mapper.InstituteRelationMapper;
import com.home.cop.sysinfo.model.InstituteRelation;
import com.home.cop.sysinfo.service.InstituteBusinessService;
import com.home.cop.sysinfo.service.InstituteRelationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
public class InstituteRelationServiceImpl implements InstituteRelationService {

    @Autowired
    private InstituteRelationMapper relationMapper;


    @Transactional
    @Override
    public List<InstituteRelation> list(Integer instId) {
        return relationMapper.list(instId);
    }

    @Transactional
    @Override
    public void modifyRelation(List<InstituteRelation> relations,Integer instId) {
        relationMapper.deleteRelation(instId);
        for (InstituteRelation relation:relations){
            relationMapper.insert(relation.getInst1Id(),relation.getInst2Id(),relation.getRelationship());
        }
    }

    @Transactional
    @Override
    public void deleteInstRelation(Integer instId) {
        relationMapper.deleteRelation(instId);
    }
}
